package Frontera;

import java.util.List;
import Entidad.Proveedores;
import Control.ControlContratarProveedor;
import DAO.ProductosJpaController;
import DAO.ProveedoresJpaController;
import Entidad.ProductoProveedor;
import Entidad.Productos;
import java.util.Vector;
import javax.persistence.EntityManager;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

public class ContratarProveedor extends javax.swing.JFrame {
    EntityManager em;
    /** Creates new form ContratarProveedor */
    public ContratarProveedor() {
         em = Splash.em;
         initComponents();
         this.jTextFieldNombre.setText(null);
         ProductosJpaController jpaProductos = new ProductosJpaController();
         List<Productos> productos = jpaProductos.getProductos(em);
         if(productos != null){
            for (Productos u: productos){
                this.jComboBox1.addItem(u.getNombreProducto());
            }
         }
                  
         modelo = new DefaultTableModel();
         tabla = new JTable(modelo);

         Vector titulos = new Vector();
         titulos.add("Nit");
         titulos.add("Nombre");
         titulos.add("Calificacion");
         titulos.add("Precio");
         modelo.setColumnIdentifiers(titulos);
         jScrollPane1.setViewportView(tabla);        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel4 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        jTextFieldNombre = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jTextFieldRepresentante = new javax.swing.JTextField();
        jTextFieldNit = new javax.swing.JTextField();
        jTextFieldProducto = new javax.swing.JTextField();
        jTextFieldDireccion = new javax.swing.JTextField();
        jTextFieldTelefono = new javax.swing.JTextField();
        jTextFieldCorreo = new javax.swing.JTextField();
        jTextFieldPagWeb = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jTextFieldCantidad = new javax.swing.JTextField();
        jTextFieldValorInd = new javax.swing.JTextField();
        jTextFieldValorTotal = new javax.swing.JTextField();
        Consultar = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        GenerarContrato = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jComboBox1 = new javax.swing.JComboBox();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel5 = new javax.swing.JLabel();
        Seleccionar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("SEP - Contratación");
        setResizable(false);

        jPanel4.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel8.setText("Nombre:");

        jTextFieldNombre.setEditable(false);

        jLabel9.setText("NIT:");

        jLabel10.setText("Representante:");

        jLabel11.setText("Producto:");

        jLabel12.setText("Direccion:");

        jLabel13.setText("Telefono:");

        jLabel14.setText("Correo:");

        jLabel15.setText("Pagina web:");

        jTextFieldRepresentante.setEditable(false);

        jTextFieldNit.setEditable(false);

        jTextFieldProducto.setEditable(false);

        jTextFieldDireccion.setEditable(false);

        jTextFieldTelefono.setEditable(false);

        jTextFieldCorreo.setEditable(false);

        jTextFieldPagWeb.setEditable(false);

        jLabel2.setText("Pedido Total:");

        jLabel3.setText("Valor individual:");

        jLabel4.setText("Valor total:");

        jTextFieldCantidad.setText("0");
        jTextFieldCantidad.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTextFieldCantidadMouseClickeed(evt);
            }
        });

        jTextFieldValorInd.setEditable(false);

        jTextFieldValorTotal.setEditable(false);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel10)
                    .addComponent(jLabel9)
                    .addComponent(jLabel11)
                    .addComponent(jLabel12)
                    .addComponent(jLabel13)
                    .addComponent(jLabel14)
                    .addComponent(jLabel15)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTextFieldNit, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 233, Short.MAX_VALUE)
                    .addComponent(jTextFieldRepresentante, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 233, Short.MAX_VALUE)
                    .addComponent(jTextFieldProducto, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 233, Short.MAX_VALUE)
                    .addComponent(jTextFieldDireccion, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 233, Short.MAX_VALUE)
                    .addComponent(jTextFieldTelefono, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 233, Short.MAX_VALUE)
                    .addComponent(jTextFieldCorreo, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 233, Short.MAX_VALUE)
                    .addComponent(jTextFieldPagWeb, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 233, Short.MAX_VALUE)
                    .addComponent(jTextFieldCantidad, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 233, Short.MAX_VALUE)
                    .addComponent(jTextFieldValorInd, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 233, Short.MAX_VALUE)
                    .addComponent(jTextFieldValorTotal, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 233, Short.MAX_VALUE)
                    .addComponent(jTextFieldNombre, javax.swing.GroupLayout.DEFAULT_SIZE, 233, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTextFieldNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jTextFieldNit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(jTextFieldRepresentante, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(jTextFieldProducto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(jTextFieldDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(jTextFieldTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14)
                    .addComponent(jTextFieldCorreo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(jTextFieldPagWeb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextFieldCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTextFieldValorInd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jTextFieldValorTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(28, Short.MAX_VALUE))
        );

        Consultar.setText("Consultar");
        Consultar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ConsultarActionPerformed(evt);
            }
        });

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel6.setText("Producto:");

        jLabel1.setFont(new java.awt.Font("Arial", 1, 18));
        jLabel1.setText("Contratación");

        GenerarContrato.setText("Generar Contrato");
        GenerarContrato.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                GenerarContratoMouseClicked(evt);
            }
        });
        GenerarContrato.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                GenerarContratoActionPerformed(evt);
            }
        });

        jButton2.setText("Volver");
        jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton2MouseClicked(evt);
            }
        });
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel5.setFont(new java.awt.Font("Arial", 1, 14));
        jLabel5.setText("Datos que se consiganrán en el contrato:");

        Seleccionar.setText("Seleccionar");
        Seleccionar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SeleccionarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(17, 17, 17)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 756, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel1)
                                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(jLabel5)))
                        .addGap(24, 24, 24)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(6, 6, 6)
                                .addComponent(jLabel6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(Consultar))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 369, Short.MAX_VALUE)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(Seleccionar)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(GenerarContrato)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(26, 26, 26)))))
                .addGap(28, 28, 28))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(jLabel1)
                .addGap(5, 5, 5)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6)
                    .addComponent(Consultar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 236, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton2)
                            .addComponent(GenerarContrato)
                            .addComponent(Seleccionar)))
                    .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(40, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton2MouseClicked
        Principal regresar = new Principal(Login.roll);
        regresar.setLocationRelativeTo(null);
        regresar.setVisible(true);
        this.dispose();
    }//GEN-LAST:event_jButton2MouseClicked

    private void GenerarContratoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_GenerarContratoMouseClicked
        Principal regresar = new Principal(Login.roll);
        regresar.setLocationRelativeTo(null);
        regresar.setVisible(true);
        this.dispose();
    }//GEN-LAST:event_GenerarContratoMouseClicked

    private void ConsultarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ConsultarActionPerformed
        while(modelo.getRowCount()>0)modelo.removeRow(0);
        ProveedoresJpaController jpaProveedores = new ProveedoresJpaController();
        List<Proveedores> listaProveedores  = jpaProveedores.getProveedores(em);
        //Vector datosBasicos = new Vector();
        ControlContratarProveedor proveedores = new ControlContratarProveedor();
        //this.tabla.removeAll();
        if(this.jComboBox1.getSelectedItem() != null)
            listaProveedores = proveedores.buscarListaProveedores(this.jComboBox1.getSelectedItem().toString(),modelo);
        else{
            JOptionPane.showMessageDialog(null, "No hay productos.", "Sistema de Evaluacion de Proveedores", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_ConsultarActionPerformed

    private void GenerarContratoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_GenerarContratoActionPerformed
            //Proveedor seleccionado con el que se hara contrato
        try {

            if(this.jTextFieldNombre.getText() == null ||  Float.valueOf(this.jTextFieldCantidad.getText()) == 0/*&& jTextField2.equals(null) && jTextField7.equals(null) && jTextField8.equals(null) &&
            jTextField9.equals(null) && jTextField11.equals(null) && jTextField12.equals(null) && jTextField13.equals(null) &&
            jTextField14.equals(null)*/){
                JOptionPane.showMessageDialog(null, "No ha indicado algun dato para generar el contrato", "Sistema de Evaluacion de Proveedores", JOptionPane.ERROR_MESSAGE);
            }
            else{
                String texto = jTextFieldCantidad.getText();
                if(Float.parseFloat(texto)>0){
                    float valorTotal = Float.parseFloat(this.jTextFieldValorInd.getText()) * Float.parseFloat(this.jTextFieldCantidad.getText());
                    this.jTextFieldValorTotal.setText(Float.toString(valorTotal));
                    ControlContratarProveedor contrato = new ControlContratarProveedor(proveedorSeleccionado, Float.parseFloat(this.jTextFieldCantidad.getText()), productoSeleccionado);
                    JOptionPane.showMessageDialog(null, contrato.generarContrato(), "Sistema de Evaluacion de Proveedores", JOptionPane.INFORMATION_MESSAGE);
                }
                else{
                    JOptionPane.showMessageDialog(null, "Cantidad invalida");
                    this.jTextFieldCantidad.setText("");
                }
            }
        }
        catch (NumberFormatException e) {
                JOptionPane.showMessageDialog(null, "Cantidad invalida");
                this.jTextFieldCantidad.setText("");
        }
    }//GEN-LAST:event_GenerarContratoActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        Principal regresarMenu = new Principal(Login.roll); //nos devuelve al Menu Principal
        regresarMenu.setLocationRelativeTo(null);
        regresarMenu.setVisible(true);
        this.dispose();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jTextFieldCantidadMouseClickeed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTextFieldCantidadMouseClickeed
        this.jTextFieldCantidad.setText(null);
    }//GEN-LAST:event_jTextFieldCantidadMouseClickeed

    private void SeleccionarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SeleccionarActionPerformed
        int filaSeleccionada = this.tabla.getSelectedRow();
        
        ControlContratarProveedor proveedores = new ControlContratarProveedor();
        if (filaSeleccionada == -1){
            JOptionPane.showMessageDialog(null, "No ha indicado el producto a ser seleccionado", "Sistema de Evaluacion de Proveedores", JOptionPane.ERROR_MESSAGE);
        }
        else{
            String ContratoGuardar = "";
            int nit = Integer.parseInt(this.modelo.getValueAt(filaSeleccionada, 0).toString());
            JOptionPane.showMessageDialog(null, proveedores.buscaProveedor(nit,proveedorSeleccionado), "Sistema de Evaluacion de Proveedores", JOptionPane.ERROR_MESSAGE);

            //Nombre:
            this.jTextFieldNombre.setText(proveedorSeleccionado.getNombre());
            ContratoGuardar = ContratoGuardar +" Nombre: "+ jTextFieldNombre.getText() + "\n";
            //Nit:
            this.jTextFieldNit.setText(String.valueOf(proveedorSeleccionado.getNit()));
            ContratoGuardar = ContratoGuardar +" Nit: "+ jTextFieldNit.getText() + "\n";
            //Representante:
            this.jTextFieldRepresentante.setText(proveedorSeleccionado.getRepresentante());
            ContratoGuardar = ContratoGuardar +" Representante: "+ jTextFieldRepresentante.getText() + "\n";
            //Producto a contratar:
            String producto = this.jComboBox1.getSelectedItem().toString();
            for (ProductoProveedor u: proveedorSeleccionado.getProductos()){
                if(u.getNombreProducto().equals(producto)){
                    productoSeleccionado = u;
                    this.jTextFieldProducto.setText(u.getNombreProducto());
                }
            }
            ContratoGuardar = ContratoGuardar +" Producto: "+ jTextFieldProducto.getText() + "\n";
            //Direccion:
            this.jTextFieldDireccion.setText(proveedorSeleccionado.getDireccion());
            ContratoGuardar = ContratoGuardar +" Direccion: "+ jTextFieldDireccion.getText() + "\n";
            //Telefono:
            this.jTextFieldTelefono.setText(String.valueOf(proveedorSeleccionado.getTelefono()));
            ContratoGuardar = ContratoGuardar +" Telefono: "+ jTextFieldTelefono.getText() + "\n";
            //Correo:
            this.jTextFieldCorreo.setText(proveedorSeleccionado.getCorreo());
            ContratoGuardar = ContratoGuardar +" Correo: "+ jTextFieldCorreo.getText() + "\n";
            //PaginaWeb:
            this.jTextFieldPagWeb.setText(proveedorSeleccionado.getPaginaWeb());
            ContratoGuardar = ContratoGuardar +" PagWeb: "+ jTextFieldPagWeb.getText() + "\n";
            //Precion del producto:
            this.jTextFieldValorInd.setText(Float.toString(productoSeleccionado.getPrecioPorUnidad()));
            ContratoGuardar = ContratoGuardar +" ValorInd: "+ jTextFieldValorInd.getText() + "\n";           
        }
    }//GEN-LAST:event_SeleccionarActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Consultar;
    private javax.swing.JButton GenerarContrato;
    private javax.swing.JButton Seleccionar;
    private javax.swing.JButton jButton2;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTextField jTextFieldCantidad;
    private javax.swing.JTextField jTextFieldCorreo;
    private javax.swing.JTextField jTextFieldDireccion;
    private javax.swing.JTextField jTextFieldNit;
    private javax.swing.JTextField jTextFieldNombre;
    private javax.swing.JTextField jTextFieldPagWeb;
    private javax.swing.JTextField jTextFieldProducto;
    private javax.swing.JTextField jTextFieldRepresentante;
    private javax.swing.JTextField jTextFieldTelefono;
    private javax.swing.JTextField jTextFieldValorInd;
    private javax.swing.JTextField jTextFieldValorTotal;
    // End of variables declaration//GEN-END:variables
    private DefaultTableModel modelo;
    private JTable tabla;
    Proveedores proveedorSeleccionado = new Proveedores();
    ProductoProveedor productoSeleccionado = new ProductoProveedor();
}
